package com.dy.controller;


import com.dy.domain.FenLei;
import com.dy.domain.pojo.PageBean;
import com.dy.domain.pojo.Result;
import com.dy.service.FenLeiService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/fenlei")
public class FenLeiController {

    @Autowired
    private FenLeiService fenLeiService;

    @RequestMapping("/findPage")
    public Result findPage(Integer pageNo, Integer pageSize, String ming){
        PageBean<FenLei> fenlei = fenLeiService.findPage(pageNo,pageSize,ming);
        return new Result().ok(fenlei);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody FenLei fenLei) throws JsonProcessingException {

        fenLeiService.add(fenLei);
        return new Result().ok(null);
    }

    @RequestMapping("/huixian")
    public Result huixian(Integer id){

        FenLei fenLei = fenLeiService.huixian(id);
        return new Result().ok(fenLei);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody FenLei fenLei) throws JsonProcessingException {
        fenLeiService.update(fenLei);
        return new Result().ok(null);
    }

    @RequestMapping("/del")
    public Result del(Integer id) throws JsonProcessingException {
        fenLeiService.del(id);
        return new Result().ok(null);
    }

    @RequestMapping("/findall")
    public Result findall() throws IOException {
        List<FenLei> fenlei = fenLeiService.findall();
        return new Result().ok(fenlei);
    }




}
